shannon <- function(x)
{
  if(!is.vector(x)==TRUE)
  {
    stop("no  vetor!")
  }
  x[x==0] <- NA
  x=na.omit(x)
  N=sum(x)
  pi=x/N
  id.sh= -sum(pi*log(pi))
  return(id.sh)
}

simpson <- function(x)
{
  if(!is.vector(x)==TRUE)
  {
    stop("no  vetor!")
  }
  x=na.omit(x)
  N=sum(x)
  pi=x/N
  id.si= sum(pi^2)
  return(id.si)
}

# 2a e 3a partes:

diversidade <- function(x, indice=c("sh", "si"))
{
  match.arg(arg=indice)
  if(indice!="sh" & indice!="si")
  {
    stop("indice incorreto")
  }
  if(!is.matrix(x)==TRUE)
  {
    stop("os dados devem ser apresentados na forma de matriz")
  }
  if(indice=="sh")
  {
    res.sh=apply(x, 2, FUN=sh)
    return(res.sh)
  }
  if(indice=="si")
  {
    res.si=apply(x, 2, FUN=si)
    return(res.si)
  }   
}










